package offerv1;

public class Offer57 {
    public int[] twoSum(int[] nums, int target) {
        int n = nums.length, left = 0, right = n - 1;
        int[] ret = new int[2];
        while (left < right) {
            int sum = nums[left] + nums[right];
            if (sum == target) {
                ret[0] = nums[left];
                ret[1] = nums[right];
                return ret;
            } else if (sum < target) {
                left++;
            } else {
                right--;
            }
        }
        return ret;
    }
}
